﻿using EkStudio.com.bean.xml.BillModule;
using EkStudio.com.bean.xml.reflection;
using EkStudio.com.bean.xml.RootInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EkStudio.com.bean.xml.BillMultiple
{
    public class BillMultipleUiGroupRoot : BillUiFormatContainer
    {
        private int maxid = 0;
        private List<BillUiGroupItems> fieldsProperties = null;

        private BillFormatModule format = null;

        [Xml]
        public int Maxid
        {
            get
            {
                return maxid;
            }

            set
            {
                maxid = value;
            }
        }

        [XmlElement]
        public List<BillUiGroupItems> FieldsProperties
        {
            get
            {
                return fieldsProperties;
            }

            set
            {
                fieldsProperties = value;
            }
        }
        [XmlTransient]
        public object ParentBean
        {
            get
            {
                return format;
            }

            set
            {
                format = value as BillFormatModule;
            }
        }

        

        public void addNode(BillUiFormatNode node, BillFormatModule format)
        {
            BillUiGroupItems it = node as BillUiGroupItems;
            if (it != null)
            {
                if (fieldsProperties == null)
                    fieldsProperties = new List<BillUiGroupItems>();
                fieldsProperties.Add(it);
            }
        }

        public void removeNode(BillUiFormatNode node)
        {
            BillUiGroupItems it = node as BillUiGroupItems;
            if (it != null)
            {
                if (fieldsProperties == null)
                    fieldsProperties = new List<BillUiGroupItems>();
                if (fieldsProperties.Contains(it))
                {
                    fieldsProperties.Remove(it);
                }
            }
        }


        public object Clone()
        {
            throw new NotImplementedException();
        }

       

        public void moveDown(BillUiFormatNode node)
        {
            throw new NotImplementedException();
        }

        public void moveUp(BillUiFormatNode node)
        {
            throw new NotImplementedException();
        }

        

        public string getNLanguageText(BillFormatModule format)
        {
            string result = "";
            int tempMaxid = Maxid + 1;
            if (format != null)
            {
                string text = ((BillModuleItem)format).BillModule.LanguageTexts;
                int index = text.IndexOf("Caption");
                int length = text.Length - 7;
                result = text.Substring(0, length);
                result = result + "Groups[" + tempMaxid + "].Caption";
            }
            this.Maxid = tempMaxid;
            return result;
        }

        public void updateLanguageText(BillFormatModule format)
        {
            this.maxid = 0;
            if (this.FieldsProperties != null && this.fieldsProperties.Count > 0)
            {
                foreach (BillUiGroupItems group in this.fieldsProperties)
                {
                    group.LanguageTexts = this.getNLanguageText(format);
                }
            }
        }



    }
}
